<template>
  <view class="container">
    <view class="content">
      <slot></slot>
    </view>
  </view>
</template>

<script setup>
// App.vue
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { useUserStore } from '@/stores'
import { message, system } from '@/utils'

const userStore = useUserStore()

onLaunch(() => {
  // 获取系统信息
  const systemInfo = system.getSystemInfo()
  console.log('App Launch - System Info:', systemInfo)

  // 监听错误事件
  uni.onError((err) => {
    console.error('App Error:', err)
  })

  checkLogin()
})

onShow(() => {
  // 获取设备信息
  const deviceInfo = system.getDeviceInfo()
  console.log('App Show - Device Info:', deviceInfo)

  // 监听主题变化
  uni.onThemeChange(({ theme }) => {
    console.log('Theme changed:', theme)
  })
})

onHide(() => {
  console.log('App Hide')
})

const checkLogin = async () => {
  try {
    const token = await uni.getStorage({ key: 'token' }) // 使用异步API
    if (!token.data) {
      throw new Error('No token')
    }
    await userStore.getUserInfo()
  } catch (error) {
    await uni.reLaunch({
      url: '/pages/login/login'
    })
  }
}
</script>

<style lang="scss">
@import '@/uni.scss';
@import '@/common/style/common.scss';

.container {
  min-height: 100vh;
  background-color: $bg-color;

  .content {
    flex: 1;
    width: 100%;
  }
}
</style>
